package com.example.springcloud.controller;

import com.example.springcloud.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chensixiang chensixiang1234@gmail.com
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/payment")
public class PaymentController {
    private final PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/ok/{id}")
    public String paymentInfo_OK(@PathVariable Integer id) {
        return paymentService.paymentInfo_OK(id) + "serverPort = " + serverPort;
    }

    @GetMapping("/timeout/{id}")
    public String paymentInfo_Timeout(@PathVariable Integer id) {
        return paymentService.paymentInfo_Timeout(id) + "serverPort = " + serverPort;
    }

    @GetMapping("/p/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
        return paymentService.paymentCircuitBreaker(id);
    }
}
